package com.test.enums;

import java.util.Arrays;
import java.util.Objects;

/**
 * 项目中异常类，此异常相关定义需要向java负责人申请
 */
public enum ResultEnum {

    /**
     * 成功
     */
    SUCCESS("10000", "成功"),
    //====公用服务============================================
    /**
     * 公共异常相关
     */
    SYSTEM_ERROR("10001","系统异常"),
    SYSTEM_BUSY("10002","系统繁忙，请稍后再试"),
    SYSTEM_UNKNOWN_ERROR("10003","未知异常"),

    SERVICE_UNUSABLE("10021","服务不可用"),
    SERVICE_ERROR("10022","服务异常"),
    SERVICE_TIMEOUT("10023","服务连接超时"),

    TOKEN_INVALID("10041","无效的token"),

    USER_INEXIST("10051","用户不存在"),
    USER_NOT_LOGIN("10052","用户未登录"),
    USER_ACCOUNT_ABNORMAL("10053"	,"用户账户异常，状态异常"),
    USER_VISIT_NOLOGIN("10054","用户未登录访问登录的数据"),

    PARAM_ERROR("10071","参数验证错误"),
    PARAM_LACK("10072","缺少参数"),
    PARAM_FORMAT_ERROR("10073","参数格式错误"),

    PASSWORD_ERROR("10091","密码错误"),
    PASSWORD_FORMAT_ERROR("10092","密码格式错误"),
    DB_STATUS_ERROR("10101","数据库状态错误"),
    DB_TYPE_ERROR("10102","数据库类型异常"),
    DB_NO_FOUND_DATA("10103","数据库找不到对应数据"),
    DB_NO_FIELD("10104","字段不存在"),
    DB_DATA_EMPTY("10107","数据异常空"),
    DB_MULTI_DATA_EXIST("10108","已存在重复数据"),
    DB_NOT_ALLOW("10110","不允许操作"),
    DB_OPERATE_NOT_ALLOW("10111","操作不允许操作的字段"),
    DB_OPERATE_ERROR("10112","操作失败"),
    DB_DATA_SAVE_ERROR("10113","数据库保存数据失败"),

    SAVE_ERROR("10151",	"保存失败"),
    DELETE_ERROR("10153",	"删除失败"),

    CLASS_NOT_FOUND("10171","找不到对应的类"),

    BALANCE_LACK("10181","余额不足"),

    IDEMPOTENT_MUTI("10191","幂等信息重复"),

    CLIENT_TYPE_ERROR("10201","错误的客户端类型"),

    CONFIG_CENTER_NOFOUND("10221","配置中心未发现"),
    CONFIG_READ_ERROR("10222","配置读取失败"),

    SORT_SKIP("10241","排序时越级、跨级"),
    TREE_LEVEL_MAX_LIMIT("10242",	"树状层级最大限制"),

    INVALID_FILE_TYPE("10251","无效的文件类型"),
    UPLOAD_FILE_FAILED("10252","文件上传失败"),

    SERVICE_SERVICE_GATEWAY_ERROR("10701","网关中心服务异常"),

    SERVICE_AUTH_ERROR("10706","认证中心服务异常"),

    SERVICE_USER_ERROR("10711","用户中心服务异常"),

    SERVICE_ADMIN_ERROR("10716","员工中心服务异常"),

    SERVICE_SETTLE_ERROR("10721","结算中心服务异常"),

    SERVICE_COORDINATE_ERROR("10726","调度中心服务异常"),

    SERVICE_SEARCH_ERROR("10731","搜索中心服务异常"),

    SERVICE_MARKET_ERROR("10736","营销中心服务异常"),

    SERVICE_THIRD_ERROR("10741","三方中心服务异常"),

    SERVICE_SYSTEM_ERROR("10746","系统设置中心服务异常"),

    SERVICE_GOODS_ERROR("10801","商品中心服务异常"),

    SERVICE_ORDER_ERROR("10805","订单中心服务异常"),

    SERVICE_QUESTION_ERROR("10811","题库中心服务异常"),

    SERVICE_AGENT_ERROR("10816","代理商中心服务异常"),

    SERVICE_AUDIT_ERROR("10821","审批中心服务异常"),

    SERVICE_CORE_ORDER_ERROR("10826","订单中心服务异常"),

    SERVICE_NEWS_ERROR("10831","新闻咨询服务异常"),

    SERVICE_CRM_ERROR("10836","CRM服务异常"),

    SERVICE_EXTENSION_ERROR("10841","推广服务异常"),

    SERVICE_WEBSOCKET_ERROR("10846","websocket服务异常"),

    SERVICE_DATACENTER_ERROR("10851","数据中心服务异常"),

    SERVICE_USERSERVICE_ERROR("10856","学服服务异常"),


    /**
     * 网关中心服务异常相关
     */
    SIGN_VERIFY_ERROR("11006","签名验证错误"),

    /**
     * 用户权限不足
     */
    PERMISSION_AUTH_ERROR("11007","权限不足"),

    /**
     * 认证中心服务异常相关
     */
    TOKEN_SIGN_VERIFY_ERROR("11105","token签名验签失败"),
    /**
     * 用户中心服务异常相关
     */
    REGIST_ERROR("11205","注册失败"),

    /**
     * 员工中心服务异常相关 暂时未定义
     */

    /**
     * 结算中心服务异常相关
     */
    ORDER_NUMBER_EXIST("11505","订单号已存在"),
    ORDER_NUMBER_ORIGIN_ERROR("11506","原支付订单号有误"),
    REFUND_FAIL("11507","退款失败"),
    ORDER_REFUND_NUMBER_EXIST("11508","退款订单号已存在"),
    /**
     * 调度中心服务异常相关
     */
    MSGID_EXIST_ERROR("11605","msgId已存在"),
    /**
     * 搜索中心服务异常相关 暂无定义
     */

    /**
     * 营销中心服务异常相关 暂无定义
     */
    /**
     * 三方中心服务异常相关
     */
    NOTE_SEND_ERROR("11905","短信发送失败"),
    API_TRILATERAL_REQUEST_ERROR("11906","第三方API请求异常"),
    SMALL_PROGRAM_WEIXIN__VERIFY_ERROR("11907","微信小程序验证失败"),
    SMALL_PROGRAM_CERTY_REQUEST_ERROR("11908","小程序登录凭证校验请求网络失败"),
    SMALL_PROGRAM_MP_DECODE_ERROR("11909","小程序手机号解密失败"),
    VERIFY_CODE_INVALID("11910","无效的验证码"),
    VERIFY_CODE_ERROR("11911","验证码错误"),
    PUBLISH_CODE_ERROR("11912","发布后不能删除"),
    PUBLISH_UPDATE_CODE_ERROR("11913","发布后不能修改"),
    /**
     * 系统设置中心服务异常相关  暂无定义
     */
    /**
     * 数据中心服务异常相关
     */


    //=======业务服务====================================
    /**
     * 商品中心服务异常相关
     */
    GOODS_BUY_PAST("15005","用户购买的商品过期"),
    GOODS_TYPE_ERROR("15006","商品类型错误"),
    /**
     * 订单中心服务相关异常
     */
    ORDER_DELIVER_NO_EXIST("15105","订单发货信息不存在"),
    ENTITY_GOODS_MUST_ADRESS("15106","请添加收货地址"),
    //ENTITY_GOODS_MUST_ADRESS("15106","实体商品必须传收货地址"),
    ORDER_AMOUNT_ERROR("15108","订单金额有误"),
    ORDER_QUERY_ERROR("15109","订单查询有误"),
    ORDER_DELIVER_QUERY_ERROR("15111","订单发货查询有误"),
    ORDER_GOODS_PAY_ERROR("15112","实体商品不能使用余额支付"),
    ORDER_REFUND_MONEY_ERROR("15113","退款金额有误"),
    QUESTION_ORDER_PRICE_ZERO_ERROR("15114","暂时没有零元商品"),
    ORDER_NOT_EXIST("15115","该订单不存在"),
    EXCEED_THE_AMOUNT_OF_THE_SUPPLEMENT("15116", "输入金额超过补费金额"),
    GOODS_NOT_FOUND_ERROR("15117", "订单关联商品记录未找到"),
    ORDER_CAN_NOT_DELETED_ERROR("15118", "该订单不支持删除"),
    ORDER_CAN_NOT_EDIT_ERROR("15119", "该订单不支持编辑"),
    ORDER_RELATE_USER_ERROR("15120","关联订单与学员信息不匹配"),
    ORDER_RELATE_GOODS_ERROR("15121","关联订单与赠课商品类型规则不匹配"),
    ORDER_RELATE_GOODS_DEL_ERROR("15122","该赠课订单关联的商品信息有误"),
    ORDER_PRICE_CHANGE_ERROR("15123","价格变更不可低于订单原应收金额"),
    ORDER_STATUS_DOES_NOT_CHANGE("15124","该订单当前状态不支持转班"),
    CHANGE_ERROR_GOODS_UNDER_REVIEW("15125","转班失败,该订单存在审核中的商品"),
    GOODS_DOES_NOT_CHANGE("15126","该商品不支持转班"),
    GOODS_DO_NOT_SUPPORT_TRANSFER("15127","该商品不支持互转"),
    ORDER_PRICE_CHANGELESS_THAN_GOODS_MIN_PRICE_ERROR("15128","价格变更不可低于商品最低价格"),
    ORDER_DELIVERY_NOT_EXIST("15129","子单原始单号不存在"),
    LOGISTICS_COMPANY_CODE_ERROR("15130","物流公司编码错误"),
    IMPORT_MORE_THAN_1000_PIECES_OF_DATA("15131","导入数据超过1000条"),
    ORDER_PAY_NOT_EXIST_ERROR("15132","订单支付流水不存在"),
    GOODS_DO_NOT_SUPPORT_CROSS_TRANSFER("15133","该商品不支持跨分校转班"),
    THE_ASSOCIATED_PAYMENT_INFORMATION_NOT_EXIST("15134","订单关联待付款信息不存在"),
    CHANGE_ERROR_GOODS_AUDIT_FAILURE("15125","转班失败,该订单存在审核失败的商品"),
    FAILED_TO_GENERATE_PAYMENT_QR_CODE("15126","生成付款二维码失败"),
    MISSING_BRANCH_INFORMATION_ERROR("15127","收款分校相关支付信息缺失"),
    ORDER_STATUS_ERROR("15128","当前订单状态无付款二维码"),
    REFUND_ORDER_APPLY_CHECK("15129","该订单存在在途的退费或转班订单,不允许发起退费申请"),
    IMPORT_DATA_CANNOT_BE_EMPTY("15130","导入数据不能为空"),
    LOGISTICS_INFORMATION_DOES_NOT_EXIST("15131","物流信息不存在"),

    /**
     * 题库中心服务异常相关
     */
    KNOWLEDGE_TREE_NODE_FORBIDDEN("15205","知识树节点已禁用"),
    KNOWLEDGE_TREE_NODE_NAME_EXIST("15206","知识树节点存在相同名字节点"),
    KNOWLEDGE_TREE_POINT_RELATION_EXIST("15207","知识树与知识点关联关系已存在"),
    KNOWLEDGE_TREE_BOTTOM_NODE_RELEVANCE_POINT("15208","知识树最底级节点才能关联知识点"),
    PUMP_TOPIC_ERROR("15209", "抽题失败"),

    /**
     * 资讯中心 15301-15400
     */

    CLASSIFY_EXIST_ERROR("15305", "分类标识已存在"),
    LABLE_EXIST_ERROR("15306", "标签标识已存在"),

    //------WARING级别错误======================================
    //------ERROR级别错误=======================================

    /**
     * 代理商15401 - 15500
     */
    BUSINESS_TYPE("15401",  "合作项目分类"),
    DATA_AGENT_TYPE("15402",  "数据代理类型"),
    COURSE_AGENT_TYPE("15403",  "课程代理类型"),
    GOODS_NOT_FIND("15404",  "未查询到该商品信息"),
    COOPERATION_STATUS("15405",  "代理机构的合作状态"),
    MOBILE_ALREADY_EXISTS("15406",  "该手机号已存在"),
    AGENT_MAX_COUNT("15407",  "子账号数量到达上限"),
    ACCOUNT_PERFORMANCE("15408",  "代理商有业绩不允许删除"),
    BUSINESS_REGION("15409",  "地区分类"),
    IDS_AND_CODES_CAN_NOT_BOTH_EXIST("15410",  "ids与codes不能同时存在"),
    ID_PHOTO_NOT_NULL("15411",  "身份证照片不能为空"),
    AGENT_NO_POWER("15413",  "代理商没权限"),
    PURCHASE_ACCOUNT_LACK("15414",  "账号不充足，无法支付!"),
    ACCNO_PASSWORD_ERROR("15415",  "账号或密码错误，请重新输入！"),
    ACCOUNT_DISABLE_ERROR("15416",  "账号异常，无法正常登录！"),
    MECHANISM_COOPERATION_TERMINATION_ERROR("15417",  "账号合作已终止，无法登录，请联系渠道经理！"),
    MECHANISM_UNCOOPERATION_ERROR("15418",  "未开启合作，无法登录！"),
    PURCHASE_BALANCE_LACK("15419",  "余额不充足，无法支付!"),
    TRANSFER_ORDER("15420",  "该订单为转班订单"),
    NORMAL_ORDER("15421",  "该订单为正常订单"),
    MECHANISM_COOPERATION_WAY_ERROR("15422",  "此项目不是课程代理合作模式!"),
    LICENSE_PHOTO_NOT_NULL("15423",  "营业执照不能为空"),
    ACCOUNT_DEFAULT_PERFORMANCE("15424",  "代理机构默认账号不允许删除"),
    COOPERATIONWAY_ERROR("15425",  "未与该项目合作或该合作模式不是课程代理合作模式"),
    ORDER_ERROR("15426",  "下单失败"),
    ORDER_PAY_ERROR("15427",  "支付金额有误"),
    TRANSFER_ERROR("15428",  "不能再次转班"),
    TRANSFER_CATEID_ERROR("15429",  "不能跨项目转班"),
    ACCOUNT_DEFAULT_NOT_FORBIDDEN("15430",  "代理机构默认账号不允许禁用"),
    ORDER_DELETE_ERROR("15431",  "已支付订单不能删除"),
    ORDER_PAYSTATUS_ERROR("15432",  "该订单已经支付!"),
    ORDER_NOPAY_ERROR("15433",  "支付中,不能重复支付!"),
    COOPERATIONWAY_STATUS_ERROR("15434",  "此项目合作状态已变更,不能转班!"),
    /**
     * 营销中心 15501 - 15600
     * 
     */
    RELEVANCE_PUBLISH_ERROR("15501",  "关联打卡必须关联一个任务"),
    /**
     * 审批流中心 15601 - 15700
     *
     */
    BUSINESS_SCENARIO_USED("15601",  "此场景正在使用，不可删除"),
    BUSINESS_ENABLE_STATUS("15602",  "业务场景启用状态，不可删除"),
    FLOW_ENABLE_STATUS("15602",  "流程启用状态，不可删除"),
    AUDIT_NUMBER_NOT_EXIST("15603","审批编号不存在！"),
    AUDIT_NO_ACCESS("15604","无权限审核！"),
    AUDIT_NO_TASK("15605","当前审核无代办任务！"),
    AUDIT_HISTORY_NO_EXIST("15606","审批流历史不存在！"),
    AUDIT_RELEASE_FAIL("15607","流程发布失败！"),
    AUDIT_ROLLBACK_FAIL("15608","审批回调失败！"),
    AUDIT_CONTENT_NOT_EXIST("15609","审批内容未找到！");

    private String code;
    private String msg;

    ResultEnum(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public String getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
    /**
     * 获取对应code枚举类
     * 当前类添加这个方法的初衷是为了给测试环境细化异常报错的颗粒度
     * @param code code
     * @return enum
     */
    public static ResultEnum get(String code) {
        return Arrays.stream(ResultEnum.values()).filter(v -> Objects.equals(v.getCode(), code)).findFirst().orElse(ResultEnum.SERVICE_SERVICE_GATEWAY_ERROR);
    }

}
